<?php
namespace home\Controller;
use Think\Controller;
use home\Controller\CommonController;
class SearchController extends Controller {
	public function index()
	{
		$str  = I('get.keywords');
		// var_dump($str);exit();
		$words = searchfenci($str);
		if(!$words){
			$this->error();
		}

		$sql = "select * from question where";

		foreach ($words as $key=> $row) {
			if($key==(count($words)-1)){
				$sql .= " title like '%$row%'";
			}else{
				$sql .= " title like '%$row%' or";
			}
			
		}

		$list = M()->query($sql);

		foreach ($list as  &$row) {
			foreach ($words as  $word) {
				$row['title'] = str_ireplace($word, "<span style='color:red'>".$word."</span>",$row['title']);
			}
		}

		
		$this->assign('list',$list);
		$this->display();
	}
}

?>